#ifndef _PROCESS_POOL_H_
#define _PROCESS_POOL_H_

#include <unistd.h>
#include "ysh.h"
#include "la.h"

#define MAX_JOB_NUM     (1024)

typedef enum JobStatus {
   JS_RUNNING, JS_STOPPED, JS_TERMINATED,
} JobStatus;
typedef JobStatus ProcessStatus;


typedef struct Job {
   //int jid;
   int                          jid;
   pid_t                        jgid;
   JobStatus                    jstatus;
   int                          jpnum;                       // Number of processes contained in the job.
   int                          jrpn;                        // Job's real process number.
   int                          jfd[2];                      // File descriptors for input and output redirection.
   char                         jstring[LINE_BUF_SIZE];
   struct Job                   *prev;
   struct Job                   *next;
} Job;

typedef struct Process {
    ProcessStatus               status;
    pid_t                       pid;
    struct Job                  *job;
    struct Process              *prev;
    struct Process              *next;
} Process;

extern int jc_status;

extern void p_init(void);
extern Process *insert_p(pid_t pid, Job *job);
extern Process *find_p(pid_t pid);
extern void delete_p(pid_t pid);
extern Job *insert_job(void);
extern Job *find_job(int jid);
extern void delete_job(Job *job);
extern Bool pool_check_status(int jid, JobStatus js);
extern void insert_history(char *item);

extern void pool_print_history(void);
extern void pool_print_jobs(void);
extern void pool_kill_all(void);

extern char StatusString[][16];

#endif

